import java.sql.*;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
    public static void main(String[] args) throws Exception{
        //1、批量处理方式：addBatch(), executeBatch(), clearBatch()
        // 2、mysql 服务器默认是关闭批处理的，我们需要通过一个参数，让mysql开启批处理支持
        // 			?rewriteBatchedStatements=true写在配置文件的url后面

        String url = "jdbc:sqlserver://localhost:1433;database=AirLine;encrypt=true;trustServerCertificate=true;rewriteBatchedStatements=true";
        String username = "sa";
        String password = "123";
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection connection=DriverManager.getConnection(url,username,password);
        PreparedStatement preparedStatement=null;
        //关闭自动提交
        connection.setAutoCommit(false);

        String q1="insert into User_Password values('用户3','123','1')";
        preparedStatement=connection.prepareStatement(q1);
        //添加新操作
        preparedStatement.addBatch();

        String q2="insert into User_Password values('用户2','123','1')";
        preparedStatement=connection.prepareStatement(q2);
        preparedStatement.addBatch();

        //批量处理
        preparedStatement.executeBatch();
        //提交
        connection.commit();

    }
}